#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int search(vector<int>& nums, int target) {
        int left = 0, right = nums.size() - 1, n = nums.size() - 1;
        if (nums[0] == target) return 0;
        if (nums[n] == target) return n;
        while (left <= right)
        {
            int m = left + ((right - left) >> 1);
            if (nums[m] == target) return m;
            if (nums[0] <= nums[m])
            {
                if (nums[0] <= target && nums[m] > target) right = m - 1;
                else left = m + 1;
            }
            else {
                if (nums[m] < target && target <= nums[n]) left = m + 1;
                else right = m - 1;
            }
        }
        return -1;
    }

    int findMin(vector<int>& nums) {
        int left = 0, right = nums.size() - 1, n = right;
        while (left < right)
        {
            int m = left + ((right - left) >> 1);
            if (nums[m] > nums[n]) left = m + 1;
            else right = m;
        }
        return nums[left];
    }
};